﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SimpleTaskManager.WebUI.Infrastructure.Abstract;
using System.Web.Security;

namespace SimpleTaskManager.WebUI.Infrastructure.Concrete
{
    /// <summary>
    /// Authentication provider using form authentication
    /// </summary>
    public class FormsAuthProvider : IAuthProvider
    {
        /// <summary>
        /// Authenticates the user with the given username and password.
        /// </summary>
        /// <param name="login">Username of the user</param>
        /// <param name="password">Password for the given username</param>
        /// <returns>Indicates whether the login informations are valid</returns>
        public bool Authenticate(string login, string password)
        {
            bool result = Membership.ValidateUser(login, password);
            if (result)
            {
                FormsAuthentication.SetAuthCookie(login, false);
            }
            return result;
        }
    }
}